<?php

/**
 * This is the model class for table "{{employee_weekly_report}}".
 *
 * The followings are the available columns in table '{{employee_weekly_report}}':
 * @property integer $id
 * @property integer $employeeId
 * @property integer $currentProjectId
 * @property string $reportWeekStartDate
 * @property string $workSummary
 * @property string $workLastWeekDescription
 * @property string $workNextWeekPlan
 * @property string $createTime
 * @property integer $createUserId
 * @property string $updateTime
 * @property integer $updateUserId
 *
 * The followings are the available model relations:
 * @property User $updateUser
 * @property User $createUser
 * @property Employee $employee
 * @property Project $currentProject
 */
class EmployeeWeeklyReport extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return EmployeeWeeklyReport the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{employee_weekly_report}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array(
				'reportWeekStartDate, workSummary',
				'required',
				'integerOnly'=>true
			),
			array('workSummary',
				'length',
				'max'=>255
			),
			array(
				'reportWeekStartDate',
				'date',
				'format' => 'yyyy-MM-dd',
			),
			array(
				'workLastWeekDescription, workNextWeekPlan',
				'safe'
			),
			//array('id, employeeId, currentProjectId, reportWeekStartDate, workSummary, workLastWeekDescription, workNextWeekPlan, createTime, createUserId, updateTime, updateUserId', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'updateUser' => array(self::BELONGS_TO, 'User', 'updateUserId'),
			'createUser' => array(self::BELONGS_TO, 'User', 'createUserId'),
			'employee' => array(self::BELONGS_TO, 'Employee', 'employeeId'),
			'currentProject' => array(self::BELONGS_TO, 'Project', 'currentProjectId'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'employeeId' => '员工',
			'currentProjectId' => '当前项目',
			'reportWeekStartDate' => '报告周',
			'workSummary' => '工作简述',
			'workLastWeekDescription' => '上周详细工作内容',
			'workNextWeekPlan' => '本周工作计划',
			'createTime' => '创建时间',
			'createUserId' => '创建用户',
			'updateTime' => '更新时间',
			'updateUserId' => '更新用户',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('employeeId',$this->employeeId);
		$criteria->compare('currentProjectId',$this->currentProjectId);
		$criteria->compare('reportWeekStartDate',$this->reportWeekStartDate,true);
		$criteria->compare('workSummary',$this->workSummary,true);
		$criteria->compare('workLastWeekDescription',$this->workLastWeekDescription,true);
		$criteria->compare('workNextWeekPlan',$this->workNextWeekPlan,true);
		$criteria->compare('createTime',$this->createTime,true);
		$criteria->compare('createUserId',$this->createUserId);
		$criteria->compare('updateTime',$this->updateTime,true);
		$criteria->compare('updateUserId',$this->updateUserId);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}